package com.kukudexin.dao;

import com.kukudexin.domain.Customer;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface CustomerDao extends JpaRepository<Customer, Long>, JpaSpecificationExecutor<Customer> {

    /**
     * 案例：根据客户名称查询客户
     *      使用jpql的形式查询
     *  jpql：from Customer where custName = ?
     *
     *  配置jpql语句，使用的@Query注解
     */
    @Query("from Customer where custName = ? ")
    Customer findJpql(String custName);

    @Query("from Customer where custId = ?1 and custName = ?2")
    Customer findCustNameAndId(long id, String zs);

    @Query(value = " update Customer set custName = ?2 where custId = ?1 ")
    @Modifying
    void updateCustomer(long custId, String custName);

    @Query(value="select * from cst_customer where cust_name like ?1",nativeQuery = true)
    List<Object[]> findSql(String custName);

    Customer findByCustName(String custName);

    List<Customer> findByCustNameLike(String custName);

    Customer findByCustNameLikeAndCustIndustry(String custName, String industrt);
}
